package com.dailyblue.java.io;

import java.io.*;

// 序列化和反序列化
public class DemoK {
    private static void a() throws IOException {
        // 1. 产生一个对象
        Student stu = new Student(1, "张三", '男');
        // 2. 将对象保存到哪里去？
        OutputStream out = new FileOutputStream("/Users/dailyblue/soft/stu.abc");
        // 3. 序列化的实际操作类
        ObjectOutputStream oos = new ObjectOutputStream(out);
        // 4. 序列化
        oos.writeObject(stu);
        oos.close();
        out.close();
    }

    private static void b() throws IOException, ClassNotFoundException {
        InputStream in = new FileInputStream("/Users/dailyblue/soft/stu.abc");
        ObjectInputStream ois = new ObjectInputStream(in);
        Object obj = ois.readObject();
        System.out.println(obj);
        ois.close();
        in.close();
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        b();
    }
}
